import axios from "axios";
// import {Toast} from "vant"
import Config from "./config";
import kingsInstance from "./instance";
import { KEYCONST, EVENT } from "./enums";
import { HttpError } from "./utils/error";
import toast from "./compoents/toast";
//创建 axios实例
var service = axios.create({
    baseURL: Config.api_service,
    // headers:{
    // 	'content-type':'application/json'
    // },
    timeout: Config.timeout //请求时间
});
/** 第二个实例 */ var service2 = axios.create({
    baseURL: Config.wallet_api_service,
    // baseURL: 'api',
    // headers:{
    // 	'content-type':'application/json'
    // },
    timeout: Config.timeout //请求时间
});
//全屏加载
var requestHandler = function(config) {
    // console.log(config, 'config打印');
    //var token = JSON.parse(localStorage.getItem(KEYCONST.token));
    var token = localStorage.getItem(KEYCONST.token);
    // var userLang = localStorage.getItem("lang");
    var userLang = "en-US";
    var currency = localStorage.getItem(KEYCONST.currency);
    // console.log(userLang, 'lang');
    if (token) {
        token = JSON.parse(token);
        //console.log('axios token', token)
        // config.headers['Authorization'] = `${token.token_type+" "+token.access_token}`;
        // config.headers['DIGITAL_TOKEN'] = (token as any).accessToken; //测试 DIGITAL-TOKEN  正式 DIGITAL_TOKEN
        config.headers["Authorization"] = "Bearer ".concat(token.accessToken);
        // debugger;
        config.headers["Accept-Currency"] = currency ? currency : "USDT";
    } else {
        config.headers["token"] = ""; //测试 DIGITAL-TOKEN  正式 DIGITAL_TOKEN
    // config.headers['DIGITAL-TOKEN'] = ''; //测试 DIGITAL-TOKEN  正式 DIGITAL_TOKEN
    }
    config.headers["Accept-Language"] = userLang;
    // config.headers['Content-Type'] = 'application/json'
    return config;
};
var requestErrorHandler = function(error) {
    kingsInstance.emit(EVENT.error, new HttpError(error));
    Promise.reject(error);
};
//request拦截器
service.interceptors.request.use(requestHandler, requestErrorHandler);
service2.interceptors.request.use(requestHandler, requestErrorHandler);
var responseHandler = function(response) {
    var code = response.status;
    if (code === 200) {
        return response.data;
    }
};
var responseErrorHandler = function(error) {
    toast.createToast({
        message: "services error",
        type: "errToast"
    });
    return Promise.reject(error);
};
//response拦截器
service.interceptors.response.use(responseHandler, responseErrorHandler);
service2.interceptors.response.use(responseHandler, responseErrorHandler);
export default service;
export var request = function(url, config) {
    return service(url, config);
};
export var request2 = function(config) {
    return service2(config);
};

 //# sourceMappingURL=axios.js.map